const util = require('../util/utils') ;
const CONFIG = require('../config/config');
const UserModel = require('../models/users');

const express = require('express');
const Router = express.Router();

//获取用户信息
Router.get('/getAllUsers',(req,res)=>{
  let conditions = {};
  UserModel.find(conditions, (error, rows) => {
    if (error) {
      console.error('Error:' + error);
    } else {
      util.jsonWrite(res, rows);
    }
  });
 
})



//获取用户信息
Router.post('/addUser',(req,res)=>{
  console.log(req.body)
  console.log(JSON.stringify(req.body))
  let { name, password, phone, email} = req.body;
  console.log(name)
    //保存到数据库
    let user = new UserModel({
      email,
      name,
      password,
      phone,
    });
    user.save().then(data => {
      util.jsonWrite(res, data);
    });
 
})


module.exports = Router; 
